﻿
$(function () {
    $("#btn_Login").click(function () {
         if (!loginValidate()) {
            return false;
        } 
    	 
        $("#desk").html("· 正在验证登录...");
        validateByServer(  $("#txt_LoginID").val(),
                $("#txt_Password").val(),Success); 
        return false;
    });
    if ($("#txt_LoginID").val().length == 0)
        $("#txt_LoginID").focus();
    else
        $("#txt_Password").focus();

});
var k = "____NewTeaching";
function Success(e) {
	
    try {
       var IsSuccess= e=="ok"; 
        if ( IsSuccess ==true) {
            //设置Cookie
           // if (result.SaveAccount==true)
              //Set(k, args.LoginID);
            //else
              //  Clear(k);
            //禁用其他按钮..
            $("input").attr("disabled", true);
            $("#desk").html("验证成功..页面正在跳转...");
            //parent.tipsClose();
            setTimeout("window.top.location='login.action';", 900);
        }
        else {
            //提示错误,.. 
            $("#desk").html("帐号或者密码错误!");
        }
    } catch (e) {
        $("#desk").html(e);
    }

}
 
function validateByServer(staffNo,pwd,callback)
{
	$.post("staffInfo!checkStaff.action",{staffNo:staffNo,staffPwd:pwd},function(data){
		callback(data); 
	},"text");
}

function Set(key, value) {
    $.cookie(key, value, { expires: 14 });
}
function Clear(key) {
    $.cookie(key, null, { expires: -1 });
}

///登录验证
function loginValidate() {
    var isValidated = false;
    if ($.trim($("#txt_LoginID").val()).length == 0) {
        setMsg("· 请输入账号<span class=\"Tips\">（如果是学生，请使用您的学号登录）</span>");
        $("#txt_LoginID").focus();
    }
    else if ($.trim($("#txt_Password").val()).length == 0) {
        setMsg("· 请输入密码 ");
        $("#txt_Password").focus();
    }
    //    else if ($.trim($("#tbxCaptcha").val()).length == 0) {
    //        alert("请输入验证码."); $("#tbxCaptcha").focus();
    //    }
    else
    { isValidated = true; }
    return isValidated;
}

function setMsg(msg) {
    $("#desk").html(msg);
}